import java.sql.*;

public class HandleErrors {
	public static void main(String[] args) {
		Connection connection = null;

			try {
				Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
				connection = DriverManager.getConnection("jdbc:pointbase:server://localhost/StaplerzDB", "pbpublic", "pbpublic");
				
				PreparedStatement selectStatement = 
					connection.prepareStatement(
							"SELECT NAME,STATUS FROM ORDERS,USERS " +
							"WHERE ORDERS.USERID=USERS.USERID " +
							"AND STATUS=?");
				
				selectStatement.setString(1, "Shipped");
				ResultSet result = selectStatement.executeQuery();
				
				while(result.next()){
					System.out.println(result.getString("status") + "\t" + result.getString("name"));
				}
				SQLWarning warning;
				warning = connection.getWarnings();
				while (warning != null) {
					warning.printStackTrace();
					warning = warning.getNextWarning();
				}
				connection.clearWarnings();
				warning = selectStatement.getWarnings();
				while (warning != null) {
					warning.printStackTrace();
					warning = warning.getNextWarning();
				}
				selectStatement.clearWarnings();
				warning = result.getWarnings();
				while (warning != null) {
					warning.printStackTrace();
					warning = warning.getNextWarning();
				}
				result.clearWarnings();
			} catch(ClassNotFoundException e) {
				e.printStackTrace();
			} catch(SQLException e) {
				for (; e != null; e = e.getNextException()) {
					e.printStackTrace();					
				}
			} catch(Exception e) {
				e.printStackTrace();				
			} finally {
				try {
					connection.close();
				} catch(SQLException e) {
					e.printStackTrace();				
				}
			}
			
	}
}
